package demo3;

public class EnumDemo {
    public static void main(String[] args) {
        // String name() 获取枚举项的名称
        System.out.println(Season.SPRING.name);
        System.out.println("-----------------------");

        // int ordinal() 返回枚举项在枚举类中的索引值
        System.out.println(Season.SPRING.ordinal());
        System.out.println(Season.SUMMER.ordinal());
        System.out.println(Season.AUTUMN.ordinal());
        System.out.println(Season.WINTER.ordinal());
        System.out.println("-----------------------");

        // int compareTo() 比较两个枚举项，返回的是索引值的差值
        System.out.println(Season.SPRING.compareTo(Season.WINTER)); // 1-4=-3
        System.out.println("-----------------------");

        // string toString() 返回枚举常量的名称
        System.out.println(Season.SPRING.toString());
        System.out.println("-----------------------");

        // valueOf(class<T>type,string name 获取指定枚举类中的指定名称的枚举值
        System.out.println(Enum.valueOf(Season.class, "SPRING"));
        System.out.println(Season.SPRING == Enum.valueOf(Season.class, "SPRING"));
        System.out.println("-----------------------");

        // values() 获得所有的枚举项
        Season[] values = Season.values();
        for (Season value : values) {
            System.out.println(value);
        }

    }
}
